package org.game.log;

import org.game.log.builder.LogDsp;
import org.game.log.dsp.PlayerActionDsp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sojoys.artifact.tools.SK_Plus;

/**
 * 玩家行为日志
 * @author win7
 *
 */
public class LogPlayerAction implements IGameLogger {

	private LogPlayerAction() {
	}

	private static LogPlayerAction ME = new LogPlayerAction();

	public static LogPlayerAction me() {
		return ME;
	}
	
    private static Logger playerAction = LoggerFactory.getLogger("playerAction");
    
    private static Logger playerLogin = LoggerFactory.getLogger("playerLogin");
    private static Logger playerLogout = LoggerFactory.getLogger("playerLogout");
    private static Logger playerLvl = LoggerFactory.getLogger("playerLvl");
    private static Logger playerRegister = LoggerFactory.getLogger("playerRegister");
    private static Logger playerGuide = LoggerFactory.getLogger("playerGuide");
    
    public void log(int pid,int onlineTime,String ip,LogDsp logDsp) {
    	SK_Plus sb = getPlayerInfo(pid);
    	addField(sb, onlineTime);
    	addField(sb, ip);
    	addField(sb, logDsp.getDsp());
        addField(sb, logDsp.build());
        if (logDsp.getDsp() == PlayerActionDsp.CREATE.getCode()) {
        	playerRegister.info(sb.e());
//		}else if (logDsp.getDsp() == PlayerActionDsp.LOGIN.getCode() || logDsp.getDsp() == PlayerActionDsp.RECONNECT.getCode()) {
//			playerLogin.info(sb.e());		
		}else if (logDsp.getDsp() == PlayerActionDsp.OFFLINE.getCode()) {
			playerLogout.info(sb.e());
		}else if (logDsp.getDsp() == PlayerActionDsp.UP_LVL.getCode()) {
			playerLvl.info(sb.e());
		}else {
			playerAction.info(sb.e());			
		}
    }
    
    public void loginLog(int pid,int onlineTime,String ip,String client_version,String device_id,String device_name,String os_version, LogDsp logDsp) {
    	SK_Plus sb = getPlayerInfo(pid);
    	addField(sb, client_version);
    	addField(sb, device_id);
    	addField(sb, device_name);
    	addField(sb, os_version);
    	addField(sb, onlineTime);
    	addField(sb, ip);
    	addField(sb, logDsp.getDsp());
        addField(sb, logDsp.build());
		playerLogin.info(sb.e());
    }
    
    
    public void playerGuideLog(int pid,String guide, LogDsp logDsp) {
    	SK_Plus sb = getPlayerInfo(pid);
    	addField(sb, guide);
    	addField(sb, logDsp.getDsp());
        addField(sb, logDsp.build());
        playerGuide.info(sb.e());
    }
}
